package com.oracle.lingshangejia.activity;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.components.Description;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry;
import com.oracle.lingshangejia.R;
import com.oracle.lingshangejia.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;


/**
 * 签约客户
 */
public class SignCstmrActivity extends BaseActivity implements View.OnClickListener {
    PieChart mp_pieChart;
    TextView tv_title;
    TextView tv_sign; //签约
    ImageButton ib_back;
    @Override
    public int intiLayout() {
        return R.layout.activity_signcstmr;
    }

    @Override
    public void initView() {
        mp_pieChart = findViewById(R.id.chart1);
        tv_title=findViewById(R.id.tv_title);
        tv_sign=findViewById(R.id.tv_sign);
        ib_back=findViewById(R.id.ib_back);
        tv_sign.setVisibility(View.VISIBLE);
        tv_title.setText("签约客户");
        tv_sign.setOnClickListener(this);
        ib_back.setOnClickListener(this);
    }

    @Override
    public void initData() {
        initPieChart();
    }
    private void initPieChart() {
        List<PieEntry> strings = new ArrayList<>();
        strings.add(new PieEntry(35f,""));
        strings.add(new PieEntry(35f,""));
        strings.add(new PieEntry(30f,""));
        PieDataSet dataSet = new PieDataSet(strings,"");

        ArrayList<Integer> colors = new ArrayList<Integer>();
        colors.add(getResources().getColor(R.color.lan));
        colors.add(getResources().getColor(R.color.huang));
        colors.add(getResources().getColor(R.color.zi));
        dataSet.setColors(colors);

        PieData pieData = new PieData(dataSet);
        pieData.setDrawValues(false);
        Description description = new Description();
        description.setText("");

        Legend l =mp_pieChart.getLegend();
        l.setEnabled(false);
        mp_pieChart.setDescription(description);
        mp_pieChart.setData(pieData);
        mp_pieChart.setDrawCenterText(true);//饼状图中间可以添加文字
        mp_pieChart.setCenterText(generateCenterSpannableText());
        mp_pieChart.invalidate();
    }
    private SpannableString generateCenterSpannableText() {

        SpannableString s = new SpannableString("236\n签约客户");
        s.setSpan(new RelativeSizeSpan(2.2f), 0, 3, 0);
        s.setSpan(new StyleSpan(Typeface.BOLD), 0, 3, 0);
        s.setSpan(new ForegroundColorSpan(Color.BLACK), 0, 3, 0);
        s.setSpan(new StyleSpan(Typeface.NORMAL), 4, s.length() - 4, 0);
       s.setSpan(new ForegroundColorSpan(Color.BLACK), 4, s.length() - 4, 0);
       s.setSpan(new RelativeSizeSpan(1.8f), 4, s.length() - 4, 0);
//        s.setSpan(new StyleSpan(Typeface.ITALIC), s.length() - 14, s.length(), 0);
//        s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), s.length() - 14, s.length(), 0);
        return s;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv_sign: //签约
                startActivity(new Intent(this,SignActivity.class));
                break;
            case R.id.ib_back: //返回
                finish();
                break;

        }
    }
}
